#include <iostream>

using namespace std;

template <class T>
class Linelist
{
public:
    Linelist(){capacity=0;}
    Linelist(int n):capacity(n)
    {  
        data=(T*)new T[capacity];
        for(int i=0;i<capacity;i++)
        {
            *(data+i)=0;
        }
    };

    ~Linelist(){};
    bool empty();
    int size();
    int  get(T element);
    void erase(int theindex);
    void insert(int theindex, T element);
    void display();
private:
    int capacity;
    T* data;
};


template <class T>
bool Linelist<T>::empty()
{
    if( capacity==0)
        return true;
    else
        return false;
};

template <class T>
int Linelist<T>::size()
{
    return capacity;
};

// FIXME: 参数`const T& element`会更好一些，下面的函数类似
template <class T>
int Linelist<T>::get(T element)
{
    int n=0;
    while(n<capacity)
    {
        if(*(data+n)==element)
        {
         break;
        }
        n++;
    }
    return n+1;
}



template <class T>
void Linelist<T>::insert(int theindex,T element)
{
    data[theindex]=element;
};

template <class T>
void Linelist<T>::erase(int theindex)
{
    for(int i=theindex;i<capacity;i++)
    {
        data[i]=data[i+1];
    }
    capacity--;
};

template <class T>
void Linelist<T>::display()
{
  for(int i=0;i<capacity;i++)
  {
      cout<<data[i]<<"  ";
  }
    cout<<endl;
};

int main()
{
    Linelist<int>  a(10);

    for(int i=0;i<4;i++)
    {
        a.insert(i,(i+1)*2);
    }

    a.display();

    a.erase(2);

    a.display();

    cout<<a.size()<<endl;

    int getelement=4;
    cout<<"the index of  "<<getelement<<" is "<<a.get(getelement)<<endl;

    system("pause");
    return 0;
}



